package com.my9yu.common.socket;

import java.net.InetSocketAddress;
import java.net.SocketAddress;

import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.my9yu.common.socket.codec.json.JsonCodecFactory;

public class Server {

	private static Logger Logger = LoggerFactory.getLogger(Server.class);

	public static void main(String[] args) throws Exception {

		Server server = new Server();
		server.start();

	}

	public Object start() throws Exception {
		Logger.info("socket服务器开始启动");
		ServerHander clientHander = new ServerHander();
		NioSocketAcceptor acceptor = new NioSocketAcceptor();

		acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new JsonCodecFactory()));

		acceptor.setHandler(clientHander);
		SocketAddress severAddress = new InetSocketAddress("127.0.0.1", 22222);
		acceptor.bind(severAddress);
		Logger.info("socket服务器启动结束");
		return "OK";

	}

}
